package com.itboye.ihomebank.activity.login;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import com.itboye.ihomebank.MainActivity;
import com.itboye.ihomebank.R;
import com.itboye.ihomebank.activity.key.ActivityGuanLiKey;
import com.itboye.ihomebank.activity.keytwo.KeyGuanLiActivity;
import com.itboye.ihomebank.activity.keytwo.KeyZuHuActivity;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

/**
 * 日志名  格式   android_用户ID_yyyy-MM-dd
 *
 * @author young
 */
public class SplashActivity extends BaseOtherActivity {
    Handler handler;
    String cy_mac;//设置的常用锁mac名称
    String cy_type;//设置的常用锁类型--0.管理员；1；普通用户；2-租户
    int lock_type;//设置的锁类型  2白马  1科技侠
    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        sendBroadcast(new Intent("login_tankuang"));
        handler.sendEmptyMessageDelayed(123, 2500);

    }

    @Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        handler.removeMessages(123);
        finish();

    }

    @Override
    public void finish() {
        // TODO Auto-generated method stub
        super.finish();
//		overridePendingTransition(0, R.anim.anim_falldown);
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    protected int layout_id() {
        // TODO Auto-generated method stub
        return R.layout.activity_splash;
    }

    @Override
    protected void onInitController() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void onInit() {
        cy_mac= (String) SPUtils.get(MyApplcation.ctx, null, SPContants.CHANGYONG_MAC, "");
        cy_type= (String) SPUtils.get(MyApplcation.ctx, null, SPContants.CHANGYONG_TYPE, "");
        lock_type= (int) SPUtils.get(MyApplcation.ctx,null,SPContants.LOCK_TYPE,0);

        // TODO Auto-generated method stub
        handler = new Handler() {
            public void handleMessage(android.os.Message msg) {
                if(!cy_mac.equals("")){
                    if (lock_type==1){//科技侠
                        Intent intent = new Intent(SplashActivity.this, ActivityGuanLiKey.class);
                        intent.putExtra("activity","two");
                        intent.putExtra("leixing",cy_type);
                        intent.putExtra(SPContants.TANKUANG,2);
                        startActivity(intent);
                    }else if (lock_type==2){//白马
                        Intent intent = new Intent(SplashActivity.this, KeyGuanLiActivity.class);
                        intent.putExtra("activity","two");
                        intent.putExtra("leixing",cy_type);
                        intent.putExtra(SPContants.TANKUANG,2);
                        startActivity(intent);
                    }

                }else{
                    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                    intent.putExtra(SPContants.TANKUANG,1);
                    startActivity(intent);
                }
                finish();
            }
            ;
        };
    }

    @Override
    protected void onReadIntent(Bundle bundle) {
        // TODO Auto-generated method stub

    }
}
